package com.example.project.utils;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class EmailUtils {

    // account uuid
    public static Map<String,String> cacheMap = new HashMap<>();


    public static void sendMimeMail(String comeTo,String comeFrom,String code,JavaMailSender javaMailSender) throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
        helper.setSubject("这是一封测试邮件");
        helper.setFrom(comeFrom);
        helper.setTo(comeTo);
        helper.setSentDate(new Date());
        helper.setText("<h1 style=\"color:red\">请在三分钟内输入验证码，验证码："+code+"+</h1>",true);
        javaMailSender.send(mimeMessage);
    }

    public static void sendSimpleMail(String comeTo,String code,JavaMailSender javaMailSender){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("验证码");
        message.setFrom("2157096371@qq.com");
        // message.setTo("1*****@qq.com","2*****qq.com");
        message.setTo(comeTo);
        message.setSentDate(new Date());
        message.setText("请在三分钟内输入验证码，验证码："+code);
        javaMailSender.send(message);
    }
}
